﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AUV5.Web.Pages
{
    public partial class Inform : PageBaseFrontend
    {

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (base.IsVerified)
                {
                    //用户头像
                    userPhoto.ImageUrl = base.VerifiedInfo.User.PhotoPath;

                    if (Request["username"] != null)
                    {
                        pUser.Visible = true;
                        Model.UserInfo user = BLL.UserInfoBLL.Instance.GetDetailByName(Request["username"].ToString());
                        if (user != null)
                        {
                            lbInformedUser.Text = user.UserName;
                            hfUserID.Value = user.UserID;
                        }
                        else
                        {
                            AlertGo("该用户不存在", URL_INDEX);
                        }
                    }
                    else if (Request["serviceID"] != null)
                    {
                        pService.Visible = true;
                        Model.ServiceInfo service = BLL.ServiceInfoBLL.Instance.GetDetail(Request["serviceID"].ToString());
                        if (service != null)
                        {
                            lbInformedService.Text = service.Title;
                        }
                        else
                        {
                            AlertGo("该服务不存在", URL_INDEX);
                        }
                    }
                    else if (Request["requestID"] != null)
                    {
                        pReqest.Visible = true;
                        Model.RequestInfo request = BLL.RequestInfoBLL.Instance.GetDetail(Request["requestID"].ToString());
                        if (request != null)
                        {
                            lbInformedRequest.Text = request.Title;
                        }
                        else
                        {
                            AlertGo("该需求不存在", URL_INDEX);
                        }
                    }
                    else if (Request["messageID"] != null)
                    {
                        pMessage.Visible = true;
                        Model.Message mes = BLL.MessageBLL.Instance.GetDetail(Request["messageID"].ToString());
                        if (mes != null)
                        {
                            lbInformedMessage.Text = mes.Content;
                        }
                        else
                        {
                            AlertGo("该信息不存在", URL_INDEX);
                        }
                    }
                    else
                    {
                        AlertGo("参数不正确！", URL_INDEX);
                    }

                }
                else
                {
                    Response.Redirect("/Pages/LoginColorBox.aspx");
                }
            }

        }

        //提交举报信息
        protected void btnAdd_Click(object sender, EventArgs e)
        {
            if (txtReason.Text.Trim() != "")
            {
                Model.InformList inform = new Model.InformList();
                inform.ListID = Guid.NewGuid().ToString();
                inform.FromUser = base.VerifiedUserID;
                inform.ToUser = hfUserID.Value;
                inform.InformReason = txtReason.Text.Trim();
                inform.RefServiceID = Request["serviceID"] ?? "";
                inform.RefRequestID = Request["requestID"] ?? "";
                inform.RefMessageID = Request["messageID"] ?? "";

                inform.State = (int)Common.Enum.auvState.Enabled;
                inform.IsDel = (int)Common.Enum.auvDel.NotDel;

                inform.CreateDate = DateTime.Now;
                inform.UpdateDate = DateTime.Now;
                inform.BeginDate = DateTime.Now;
                inform.EndDate = DateTime.Now;
                BLL.InformListBLL.Instance.Add(inform);

                //添加到黑名单
                if (!string.IsNullOrEmpty(inform.RefMessageID) && ckbBlackList.Checked)
                {
                    Model.Message mes = BLL.MessageBLL.Instance.GetDetail(Request["messageID"].ToString());
                    if (mes != null)
                    {
                        Model.BlackList blist = new Model.BlackList();
                        blist.ListID = Guid.NewGuid().ToString();
                        blist.UserID = base.VerifiedUserID;
                        blist.BlackUser = mes.Sender;
                        BLL.BlackListBLL.Instance.Add(blist);
                    }
                }
                base.SuccessInfo = "举报成功！友情提示：同一内容请勿重复举报！";
                base.CloseThickBox(true);
            }
            else
            {
                lbMessage.Text = "请输入举报的原因";
            }
        }

        //快速填写举报理由
        protected void lboxReason_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtReason.Text = lboxReason.SelectedItem.Value;
        }

    }
}